<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<input type="button" value="平方" onclick="f()">
<h3>
  结果:<span></span>
</h3>
<script>
  let i = document.querySelector("input");
  let s = document.querySelector("span");
  function f() {
    //判断输入的内容是否是数值
    if (isNaN(i.value)){
      s.innerText = "输入错误!";
      return;
    }
    //字符串在进行-*/运算时会自动转成数值类型
    // s.innerText = i.value*i.value;
    //把字符串转成数值 后再进行加法运算
    // s.innerText = parseFloat(i.value)+parseFloat(i.value);
    s.innerText = i.value*1+i.value*1;
  }
</script>
</body>
</html>